import java.io.Serializable;

class MarkovPTableEntry implements Comparable<MarkovPTableEntry>, Serializable
{
	private static final long serialVersionUID = 3053266341242482553L;
	private MarkovState state;
	private Integer frequency;
	
	/**
	 * Creates a MarkovPTableEntry
	 * 
	 * @param newState <code>MarkovState</code>
	 * @param freq <code>Integer</code>
	 */
	public MarkovPTableEntry(MarkovState newState, Integer freq)
	{
		if(MarkovModel.VERBOSITY == 3)
			System.out.println("ENTER: MarkovPTableEntry.MarkovPTableEntry ()");
		
		state = newState;
		frequency = freq;
		

		if(MarkovModel.VERBOSITY == 3)
			System.out.println("EXIT: MarkovPTableEntry.MarkovPTableEntry ()");
	}
	
	@Override
	/**
	 * Comparison for sort
	 */
	public int compareTo(MarkovPTableEntry tempEntry) 
	{
		if(frequency < tempEntry.getFrequency())
		{
			return -1;
		}
		else if(frequency > tempEntry.getFrequency())
		{
			return 1;
		}
		
		return 0;
	}

	/**
	 * Returns the number of times this MarkovState has been accepted
	 * 
	 * @return <code>Integer</code>
	 */
	public Integer getFrequency()
	{
		if(MarkovModel.VERBOSITY == 3)
			System.out.println("ENTER: MarkovPTableEntry.getFrequency ()");
		

		if(MarkovModel.VERBOSITY == 3)
			System.out.println("EXIT: MarkovPTableEntry.getFrequency ("+frequency+")");
		return frequency;
	}
	
	/**
	 * Get the <code>MarkovState</code> for this 
	 * <code>MarkovPTableEntry</code>.
	 * 
	 * @return <code>MarkovState</code>
	 */
	public MarkovState getState()
	{
		if(MarkovModel.VERBOSITY == 3)
			System.out.println("ENTER: MarkovPTableEntry.getState ()");
		
		
		if(MarkovModel.VERBOSITY == 3)
			System.out.println("EXIT: MarkovPTableEntry.getState ()");
		return state;
	}
	
	/**
	 * Increases the frequency of the appropriate MarkovState by
	 * one occurrence
	 */
	public void increaseFrequency()
	{
		if(MarkovModel.VERBOSITY == 3)
			System.out.println("ENTER: MarkovPTableEntry.increaseFrequency ()");
		
		frequency++;
	
		if(MarkovModel.VERBOSITY == 3)
			System.out.println("EXIT: MarkovPTableEntry.increaseFrequency ()");
	}
	public void setState(MarkovState state)
	{
		this.state = state;
	}
	@Override
	public String toString()
	{
		return "MarkovPTableEntry@"+this.hashCode()+
			"=(state="+state+",frequency="+frequency+")";
	}
}